<template>
  <div class="discount-content">
    <van-cell-group>
      <van-field v-model="money" placeholder="请输入优惠券金额" type="number" label="金额"/>
      <van-field v-model="manmoney" type="number" placeholder="请输入优惠券使用门槛" label="门槛金额"/>
      <van-field v-model="creattime" @focus="showcreate = true" placeholder="请选择生效时间" label="生效时间"/>
      <van-field v-model="stoptime" @focus="showend = true" placeholder="请选择失效时间" label="失效时间"/>
      <van-field v-model="nums" @focus="showend = true" placeholder="请输入张数" label="张数"/>
    </van-cell-group>
    <!-- <div class="opabtn" @click="showcreate = true">这事开始时间</div>
    <div class="opabtn2" @click="showend = true">这是结束时间</div>-->
    <!-- <van-radio-group v-model="radio" >
    <van-cell title="满减券" clickable @click="radio = '1'">
      <van-radio name="1" checked-color="#fe9a0f"/>
    </van-cell>
    <van-cell title="优惠券" clickable @click="radio = '2'">
      <van-radio name="2" checked-color="#fe9a0f"/>
    </van-cell>
    </van-radio-group>-->
    <div class="savebtn" @click="Suk_savebtn">保存</div>
    <van-popup v-model="showcreate" position="bottom">
      <van-datetime-picker
        v-model="currentDate"
        type="date"
        :min-date="minDate"
        @confirm="checkcratetime"
        @cancel="showcreate = false"
      />
    </van-popup>

    <van-popup v-model="showend" position="bottom">
      <van-datetime-picker
        v-model="currentDate"
        type="date"
        :min-date="minDate"
        @confirm="checkendtime"
        @cancel="showend = false"
      />
    </van-popup>
    <router-link to="shopcount">
      <div class="checkmydis">查看我的优惠券</div>
    </router-link>
  </div>
</template>
<script>
export default {
  data() {
    return {
      showend: false,
      showcreate: false,
      minDate: new Date(),
      currentDate: new Date(),
      radio: "1",
      money: "",
      manmoney: "",
      creattime: "",
      stoptime: "",
      nums:999
    };
  },
  beforeCreate: function() {
    //创建前
  },
  create: function() {
    //创建后
  },
  beforeMount: function() {
    //挂载前
  },
  mounted: function() {
    //挂载后
  },
  beforeUpdate: function() {
    //更新前
  },
  update: function() {
    //更新后
  },
  methods: {
    //  formatter(type, value) {
    //   if (type === 'year') {
    //     return `${value}年`;
    //   } else if (type === 'month') {
    //     return `${value}月`
    //   }
    //   return value;
    // },
    // 下面的是我们的开始时间
    checkcratetime(e) {
      let create = e.toLocaleDateString();
      console.log(create.replace(/\//g, "-"));
      this.creattime = create.replace(/\//g, "-");
      this.showcreate = false;
    },
    checkendtime(e) {
      let end = e.toLocaleDateString();
      console.log(end.replace(/\//g, "-"));
      this.stoptime = end.replace(/\//g, "-");
      this.showend = false;
    },
    Suk_savebtn() {
      let that = this;
      that.$toast.loading({
        message: "加载中..."
      });
      var Sukdata = {
        money: that.money,
        total: that.manmoney,
        stoptime: that.stoptime,
        createtime: that.creattime,
        nums:that.nums,
        diningId: localStorage.getItem("myshopid")
      };
      console.log(Sukdata);
      that.axios
        .post(that.baseUrl + "/coupon/manCoupon", that.Qs.stringify(Sukdata), {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(function(res) {
          if (res.request.status === 200) {
            if (res.data.meta.code == 200) {
              if (res.data.meta.msg == "OK") {
                that.$toast.success({
                  message: "添加成功！"
                });
                that.$router.go(-1);
              }
            } else if (res.data.meta.code == 501) {
            }
          }
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.discount-content {
  font-size: 0.3rem;
  background: #f0f0f0;
  padding-bottom: 13rem;
}

.savebtn {
  width: 8.5rem;
  height: 1.1rem;
  background: #fe9a0f;
  margin: 2rem auto;
  border-radius: 0.3rem;
  line-height: 1.1rem;
  text-align: center;
  font-size: 0.54rem;
  color: #fff;
  font-size: 0.4rem;
}

.opabtn {
  width: 100%;
  height: 1.1rem;
  background: red;
  position: absolute;
  opacity: 0;
  top: 3.5rem;
  z-index: 999;
}

.opabtn2 {
  width: 100%;
  height: 1.1rem;
  opacity: 0;
  position: absolute;
  top: 4.6rem;
  z-index: 999;
}

.checkmydis {
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 1.3rem;
  line-height: 1.3rem;
  color: #fff;
  text-align: center;
  background: #ff9910;
  margin: 0 auto;
}
</style>
